﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            //连接字符串
            string ConnStr = "server = .;database=School;uid=sa;Pwd=lsy6796159..";
            //声明连接对象
            SqlConnection sqlconn = new SqlConnection(ConnStr);
            //打开连接
            sqlconn.Open();
            //声明sql指令
            string sql = "select * from StudentInfo";
            //声明指令对象
            SqlCommand SqlCmm = new SqlCommand(sql, sqlconn);
            SqlDataReader SqlDR = SqlCmm.ExecuteReader();
            while(SqlDR.Read()){
                int StudentID = (int)SqlDR["StudentID"];
                string StudentName = (string)SqlDR["StudentName"];
                string StudentSex = (string)SqlDR["StudentSex"];
                int StudentAge = (int)SqlDR["StudentAge"];
                string StudentScore = (string)SqlDR["StudentScore"];
                Console.WriteLine("学生编号\t"+StudentID+"\t学生姓名\t"+StudentName+"\t学生性别\t"+StudentSex+"\t学生年龄\t"+StudentAge+"\t学生成绩\t"+StudentScore);
            }
             sqlconn.Close();
             
            
            
        }
    }
}
